home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / msdos / viewers / pvquan16 / vga / vga200.c < prev    next >
C/C++ Source or Header  |  1992-11-30  |  4KB  |  121 lines

  1. /************************************************************************
  2.  *                                                                      *
  3.  *                  Copyright (c) 1991, Frank van der Hulst             *
  4.  *                          All Rights Reserved                         *
  5.  *                                                                      *
  6.  * Authors:                                                             *
  7.  *          FvdH - Frank van der Hulst (Wellington, NZ)                     *
  8.  *                                                                      *
  9.  * Versions:                                                            *
  10.  *    V1.1 910626 FvdH - QUANT released for DBW_RENDER                    *
  11.  *    V1.2 911021 FvdH - QUANT released for PoV Ray                      *
  12.  *    V1.3 911030 FvdH - Added 320x200x256x4 pages support                    *
  13.  *                                                                      *
  14.  ************************************************************************/
  15. /*
  16.  
  17. VGA 320 * 200 * 256 mode display module.
  18.  
  19. This code is based on an assembler source file by K. Heidenstrom.
  20. It contains routines to display images in 320*200 mode by modifying
  21. the VGA registers.
  22.  
  23. Advantages of 320 * 200:
  24. -    Four separate video pages which can be displayed independently.
  25.     These contain two views of a scene, taken from slightly different
  26.     viewpoints. These are displayed alternately on the screen, in sync with
  27.     a pair of "chopper glasses", to give a 3D effect. Four pages allows
  28.     double-buffered animation.
  29.  
  30. -    Less than 64K bytes per image
  31. */
  32.  
  33. #include <dos.h>
  34. #include <mem.h>
  35.  
  36. #include "vga.h"
  37.  
  38. #define SC_INDEX           0x3c4
  39. #define GC_INDEX           0x3ce
  40. #define CRTC_INDEX         0x3d4
  41.  
  42. #define VGA_SEGMENT            0xa000
  43. #define MAP_MASK           2
  44. #define MEMORY_MODE        4
  45. #define GRAPHICS_MODE      5
  46. #define MISCELLANEOUS      6
  47. #define MAX_SCAN_LINE      9
  48. #define START_ADDRESS_HIGH 0x0c
  49. #define UNDERLINE          0x14
  50. #define MODE_CONTROL       0x17
  51.  
  52. static unsigned int act_segment = VGA_SEGMENT;            /* Current page being written to */
  53.  
  54. void putpixel_200(unsigned int x, unsigned int y, unsigned char colour)
  55. {
  56.     char far *addr;
  57.  
  58.     addr = MK_FP(act_segment, y * (320/4) + x/4);
  59.     outport(SC_INDEX, (0x0100 << (x & 3)) | MAP_MASK);    /* Write to only 1 plane */
  60.     *addr = colour;
  61. }
  62.  
  63. void set320x200x4mode(void)
  64. {
  65.     struct REGPACK regs;
  66.  
  67.     regs.r_ax = 0x13;                /* Set 320*200*256 graphics mode via BIOS */
  68.     intr(0x10, ®s);
  69.  
  70. /* Setup Sequencer - disable Chain 4 bit for bitplane-architecture
  71.     memory map */
  72.  
  73.     outport(SC_INDEX, 0x604);        /* Sequencer -- disable 'Chain 4' bit */
  74.  
  75. /* Set up CRTC for special video mode */
  76.  
  77.     outport(CRTC_INDEX, 0xe317);    /* CRTC -- Select "byte mode" */
  78.     outport(CRTC_INDEX, 20);        /* Turn off "double word mode" */
  79.  
  80. /* Set up Graphics Controller for 256-colour mode, write mode 0, replace mode
  81.     Following is default setup anyway - not strictly needed */
  82.  
  83.     outport(GC_INDEX, 0x4005);            /* Graphics controller address register */
  84.                                             /* 256-colour mode, write mode zero */
  85.     outport(GC_INDEX, 3);                /* Replace pixel values */
  86.  
  87. /* Now clear the whole screen, since the mode 13h set only clears 64K. Do this
  88.     before switching CRTC out of mode 13h, so that we don't see garbage on the
  89.     screen. */
  90.  
  91.     outport(SC_INDEX, 0x0f00 | MAP_MASK);            /* Write to 4 planes at once */
  92.     setmem(MK_FP(VGA_SEGMENT, 0), 0xffff, 0);
  93. }
  94.  
  95. void set320x200x1mode(void)
  96. {
  97.     struct REGPACK regs;
  98.  
  99.     regs.r_ax = 0x13;                /* Set 320*200*256 graphics mode via BIOS */
  100.     intr(0x10, ®s);
  101. }
  102.  
  103. void end320x200mode(void)
  104. {
  105.     struct REGPACK regs;
  106.  
  107.     regs.r_ax = 3;                /* Return to text mode */
  108.     intr(0x10, ®s);
  109. }
  110.  
  111. void setvis_200(int page)
  112. {
  113.     outport(CRTC_INDEX, (page << 14) | 0x0c);
  114. }
  115.  
  116. char far *setact_200(int page)
  117. {
  118.     act_segment = VGA_SEGMENT + (page << 10);
  119.     return MK_FP(act_segment, 0);
  120. }
  121.